using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CoinUI : MonoBehaviour
{
    public  Text scoreText;
    public  Text totalText;
    private int  totalCoins;//所有金币数量
    public  Text endGameText;
    private void OnEnable()
    {
        CoinEvent.onScoreChange += UpdateScoreText;
        CoinEvent.onCoinChange  += UpdateNumText;
    }

    private void OnDisable()
    {
        CoinEvent.onScoreChange -= UpdateScoreText;
        CoinEvent.onCoinChange  -= UpdateNumText;
    }
    private void UpdateScoreText(int score)
    {
        scoreText.text = "Score: " + score;
    }
    private void UpdateNumText(int coinNum)
    {
        totalText.text = "Total: " + coinNum;
        if (coinNum<=0)
        {
            EndGame();
        }
    }
    private void EndGame()
    {
        endGameText.text = "Game Over!";
    }
}
